package cn.fzkj.future06;

import akka.actor.AbstractActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;

/**
 * @ author mr
 * @ description
 * @ since 2024/12/2
 */
public class WorkerActor extends AbstractActor {

    private final LoggingAdapter log = Logging.getLogger(getContext().system(), this);

    @Override
    public Receive createReceive() {
        log.info("akka.future.WorkerActor.onReceive:");
        return receiveBuilder()
                .match(Integer.class, msg -> {
                    Thread.sleep(1000);
                    int i = Integer.parseInt(msg.toString());
                    getSender().tell(i*i, getSelf());
                })
                .matchAny(this::unhandled)
                .build();
    }
}
